/**
 * jquery.multiform.js
 * @author yangdongqi <yangdongqi@hayzone.com>
 * @version 1.0 2011-08-18 23:28
 * @package lib.widgets
 */
;(function($) {
	$.extend({
		'multiform': function(params) {
			var paramrs = params;
			var embedId = params.embedId;
			var addButtons = params.addButtons;
			var removeButtonClass = params.removeButtonClass;
			var formId = params.formId;
			var templateId = params.templateId;
			var itemClass = params.itemClass;
			var hiddenName = params.hiddenName;
			
			init();
			function init() {
				for(i=0; i<addButtons.length; ++i) {
					$(addButtons[i]).live('click', function(){
						$ele = $('#'+templateId).clone();
						$ele.removeAttr('id');
						$ele.addClass(itemClass);
						index = new Date().getTime();
						$ele.attr('index', index);
						$ele.find('.'+removeButtonClass).attr('index', index);
						$('#'+embedId).append($ele);
						$ele.show();
					})
				}
				$('.'+removeButtonClass).live('click', function() {
					index = $(this).attr('index');
					$('.'+itemClass+'[index="'+index+'"]').remove();
					$('#'+formId).append("<input type='hidden' name='"+hiddenName+"' value='"+index+"'>");
				})
			}
			
			
		}
	});
})(jQuery);
